//用户详情页
var server = require('../../utils/server');
var common = require('../../utils/common');
Page({
  data: {
    editable: false,
    date: '请选择(保存后不可修改)',
    userInfo: [],
    malchecked: false,
    fachecked: false
  },
  onLoad: function () {
    this.getUserInfo();
  },
  getUserInfo: function () {
    server.postJSON(common.basePath + 'my/getinfo', '', res => {
      if (res.data.errno == '0') {
        this.data.gender = res.data.data.gender;
        this.setData({
          userInfo: res.data.data
        })
        if (res.data.data.birthday != "") {
          this.setData({
            date: res.data.data.birthday
          })
        }
        if (res.data.data.gender == "0") {
          this.setData({
            fachecked: true,
          })
        } else {
          this.setData({
            malchecked: true
          })
        }
      } else {
        common.showErrorToast(res.data.errmsg);
      }
    })
  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  sexChange(e) {
    this.data.gender = e.detail.value;
  },
  formSubmit: function (e) {
    var editParam = {
      "name": e.detail.value.name,
      "birthday": this.data.date,
      "gender": this.data.gender,
      "address": e.detail.value.address
    }
    if (this.data.date == "请选择(保存后不可修改)") {
      common.showToast("生日不能为空！")
    } else if (e.detail.value.address == "") {
      common.showToast("联系地址不能为空！")
    } else {
      server.postJSON(common.basePath + 'my/updateinfo', editParam, res => {
        if (res.data.errno == "0") {
          common.showToast("保存成功");
          wx.switchTab({
            url: '../../pages/user_center/userinfoIndex',
          })
        } else {
          common.showErrorToast(res.data.errmsg);
        }
      })
    }
  },

})